<?php
namespace Users\Model;

use Zend\Db\ResultSet\ResultSet;
use Zend\Db\TableGateway\TableGateway;
use Zend\Db\Sql;
use Zend\Db\Sql\Where;
use Zend\Db\Sql\Select;
use Zend\Paginator\Adapter\DbSelect;
use Zend\Paginator\Paginator;
use Zend\Db\Sql\Predicate;
use Zend\Db\Sql\Expression;

class OrderMainsTable
{
    protected $tableGateway;
	protected $select;
    public function __construct(TableGateway $tableGateway)
    {
        $this->tableGateway = $tableGateway;
		$this->select = new Select();
    }		
	public function addOrder($orderId,$mainArray)
    {	
		if(isset($mainArray['dropCategory']) && $mainArray['dropCategory']!=''){
			$cat_id=$mainArray['dropCategory'];
		}else{
			$cat_id='';
		}
		if(isset($mainArray['dropSubCategory']) && $mainArray['dropSubCategory']!=''){
			$sub_cat_id=$mainArray['dropSubCategory'];
		}else{
			$sub_cat_id='';
		}
		if(isset($mainArray['categoryText']) && $mainArray['categoryText']!=''){
			$new_cat_name=$mainArray['categoryText'];
		}else{
			$new_cat_name='';
		}
		if(isset($mainArray['subCategoryText']) && $mainArray['subCategoryText']!=''){
			$new_sub_cat_name=$mainArray['subCategoryText'];
		}else{
			$new_sub_cat_name='';
		}
		if(isset($_SESSION['admin']['user_type_id']) && $_SESSION['admin']['user_type_id']=='1'){
			$guest_email=$mainArray['guest_email'];
			$guest_phone=$mainArray['guest_phone'];
		}else if(isset($_SESSION['user']['user_type_id']) && $_SESSION['user']['user_type_id']=='2'){
			$guest_email=$mainArray['guest_email'];
			$guest_phone=$mainArray['guest_phone'];
		}else if(isset($_SESSION['user']['user_type_id']) && $_SESSION['user']['user_type_id']=='3'){
			$guest_email='';
			$guest_phone='';
		}
		$data = array(
			'ads_order_id' 	    => $orderId, 	
			'category_id' 	    => $cat_id,  		
			'district_id' 	    => $mainArray['districts'], 	
			'area_id'           => $mainArray['areas'],  	
			'language_id' 	    => $mainArray['language'],   
			'location_id' 	    => $mainArray['location'],   
			'sub_cat_id'	    => $sub_cat_id, 	
			'new_category'  	=> $new_cat_name,
			'new_sub_category' 	=> $new_sub_cat_name,
			'status' 	        => 0,
			'added_date' 	    => date('Y-m-d H:i:s'),
			'updated_date' 	    => date('Y-m-d H:i:s'), 
			'guest_email' 	       => $guest_email, 		
			'guest_phone_number'   => $guest_phone, 	
		);		
		$this->tableGateway->insert($data);
		return $this->tableGateway->lastInsertValue;	
    }
	public function changeStatus($oderIds,$value)
	{
		$data = array(
			'status'       =>$value,
		);
		$updateStatus=$this->tableGateway->update($data,array('(ads_order_id IN ('.$oderIds.'))'));
		return 	$updateStatus;			
	}
}